Completed
Push — master ( 02c732...1cf8a6 )
by Grant
04:10 queued 10s
created

JobPostAPI.populateJobPoster   C

Complexity

Conditions 10
Paths 256

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 256
nop 1
dl 0
loc 1
rs 5.9999
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like JobPostAPI.populateJobPoster often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
7
8
var JobPostAPI = {};
9
//JobPostAPI.jobPosts = [];
10
11
12
JobPostAPI.version = "v1";
13
//API url
14
JobPostAPI.baseURL = "/tc/api/"+JobPostAPI.version+"";
15
16
/**
17
 *
18
 * @returns {JobPostAPI.JobPost}
19
 */
20
JobPostAPI.JobPost = function(
21
    id,manager_user_id,title,applicants_to_date,close_date_time,department,branch,division,location_city,location_province,
22
    term_qty,term_units,remuneration_type,remuneration_range_low,remuneration_range_high,impact,key_tasks,core_competencies,
23
    developing_competencies,questions,noc,classification,security_clearance,language_requirement,start_date){
24
    this.id = id;
25
    this.manager_user_id = manager_user_id;
26
    this.title = title;
27
    this.applicants_to_date = applicants_to_date;
28
    this.close_date_time = close_date_time;
29
    this.department = department;
30
    this.branch = branch;
31
    this.division = division;
32
    this.location_city = location_city;
33
    this.location_province = location_province;
34
    this.term_qty = term_qty;
35
    this.term_units = term_units;
36
    this.remuneration_type = remuneration_type;
37
    this.remuneration_range_low = remuneration_range_low;
38
    this.remuneration_range_high = remuneration_range_high;
39
    this.impact = impact;
40
    this.key_tasks = key_tasks;
41
    this.core_competencies = core_competencies;
42
    this.developing_competencies = developing_competencies;
43
    this.questions = questions;
44
    this.noc = noc;
45
    this.classification = classification;
46
    this.security_clearance = security_clearance;
47
    this.language_requirement = language_requirement;
48
    this.start_date = start_date;
49
};
50
51
JobPostAPI.JobPosterQuestion = function(id, question, description) {
52
    this.id = id;
53
    this.question = question;
54
    this.description = description;
55
};
56
57
JobPostAPI.showBrowseJobs = function() {
58
    var stateInfo = {pageInfo: 'browse_jobs', pageTitle: 'Talent Cloud: Browse Jobs'};
59
    document.title = stateInfo.pageTitle;
60
    history.pushState(stateInfo, stateInfo.pageInfo, '#BrowseJobs');
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
61
62
    TalentCloudAPI.hideAllContent();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
63
64
    var browseJobsSection = document.getElementById('browseJobsSection');
65
    browseJobsSection.classList.remove('hidden');
66
67
    var loadingJobs = document.getElementById("loadingJobs");
68
    loadingJobs.classList.remove("hidden");
69
70
    DataAPI.getJobs(JobPostAPI.populateJobObjectList);
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
71
72
    //AccessibilityAPI.focusElement("topPage");
73
74
    // New Subpage Hero Scripts
75
76
    Utilities.getHeroElements();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
77
78
    var browseHeroTitle = document.getElementById("browseHeroTitle");
79
    browseHeroTitle.classList.remove("hidden");
80
    browseHeroTitle.setAttribute("aria-hidden", "false");
81
82
    // Mobile Menu Overflow Release
83
    document.body.style.overflowY = "visible";
84
85
    // Google Analytics
86
87
    ga('set', 'page', '/browse-jobs');
88
    ga('send', 'pageview');
89
90
};
91
92
/**
93
 *
94
 * @param {type} data
95
 * @returns {undefined}
96
 */
97
JobPostAPI.populateJobObjectList = function(xhr_response){
98
    var data = JSON.parse(xhr_response.responseText);
99
    Utilities.debug?console.log("populating job Objects"):null;
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
100
    Utilities.debug?console.log(data):null;
0 ignored issues
show
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
101
102
    var jobs = data.jobs;
103
    //var jobs = data.response.jsonBody.job;
104
    jobPosts = [];
0 ignored issues
show
Bug introduced by
The variable jobPosts seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.jobPosts.
Loading history...
105
106
    for(var job in jobs){
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
107
108
        Utilities.debug?console.log(jobs[job]):null;
0 ignored issues
show
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
109
110
        var job = JobPostAPI.populateJobObject(jobs[job]);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable job already seems to be declared on line 106. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like job was already defined.
Loading history...
111
112
        jobPosts.push(job);
113
    }
114
115
    JobPostAPI.populateJobs(jobPosts);
116
117
};
118
119
/**
120
 *
121
 * @param {json} JSONJob
122
 * @returns JobPostAPI.JobPost
123
 */
124
JobPostAPI.populateJobObject = function(JSONJob){
125
126
    Utilities.debug?console.log("populating job Objects"):null;
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
127
    Utilities.debug?console.log(JSONJob):null;
0 ignored issues
show
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
128
    //console.log(JSONJob);
129
    var job = JSONJob;
130
131
    Utilities.debug?console.log(job):null;
0 ignored issues
show
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
132
    //console.log(job);
133
    var jobObj = new JobPostAPI.JobPost();
134
135
    jobObj.id = job.id;
136
    jobObj.manager_user_id = job.manager_user_id;
137
    jobObj.title = job.title;
138
    jobObj.applicants_to_date = job.applicants_to_date;
139
    jobObj.close_date_time = job.close_date;
140
    jobObj.department = job.department;
141
    jobObj.branch = job.branch;
142
    jobObj.division = job.division;
143
    jobObj.location_city = job.location_city;
144
    jobObj.location_province = job.location_province;
145
    jobObj.term_qty = job.term_qty;
146
    jobObj.term_units = job.term_units;
147
    jobObj.remuneration_type = job.remuneration_type;
148
    jobObj.remuneration_range_low = job.remuneration_range_low;
149
    jobObj.remuneration_range_high = job.remuneration_range_high;
150
    jobObj.impact = job.impact;
151
    jobObj.key_tasks = job.key_tasks;
152
    jobObj.core_competencies = job.core_competencies;
153
    jobObj.developing_competencies = job.developing_competencies;
154
    jobObj.questions = [];
155
    for(var i=0; i<job.questions.length; i++) {
156
        var jsonQuesion = job.questions[i];
157
        var question = new JobPostAPI.JobPosterQuestion(jsonQuesion.id, jsonQuesion.question, jsonQuesion.description);
158
        jobObj.questions.push(question);
159
    }
160
161
    jobObj.noc = job.noc;
162
163
    // TAL-150
164
    jobObj.classification = job.classification;
165
    jobObj.security_clearance = job.security_clearance;
166
    jobObj.language_requirement = job.language_requirement;
167
    jobObj.start_date = job.start_date;
168
169
170
    Utilities.debug?console.log(jobObj):null;
0 ignored issues
show
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
171
172
    return jobObj;
173
};
174
175
/**
176
 *
177
 * @returns {undefined}
178
 */
179
JobPostAPI.populateJobs = function(jobPosts){
180
    Utilities.debug?console.log("populating jobs"):null;
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
181
    var jobsWrapper = document.getElementById("jobList");
182
    var jobsDiv = document.getElementById("browseJobsList");
183
    var noJobs = document.getElementById("noJobs");
184
    var loadingJobs = document.getElementById("loadingJobs");
185
186
    var browseJobsSection = document.getElementById("browseJobsSection");
187
    browseJobsSection.classList.remove("hidden");
188
189
    //Remove previously shown jobs
190
    while (jobsDiv.lastChild) {
191
        jobsDiv.removeChild(jobsDiv.lastChild);
192
    }
193
    var locale = TalentCloudAPI.getLanguageFromCookie().toString();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
194
    for(var j = 0; j < jobPosts.length; j++){
195
        var job = jobPosts[j];
196
        jobsDiv.appendChild(JobPostAPI.populateJobSummary(job, false, locale));
197
    }
198
199
    loadingJobs.classList.add("hidden");
200
    if(jobPosts.length > 0){
201
        jobsWrapper.classList.remove("hidden");
202
        noJobs.classList.add("hidden");
203
    } else {
204
        jobsWrapper.classList.add("hidden");
205
        noJobs.classList.remove("hidden");
206
    }
207
208
    EventsAPI.hideBodyOverflow(false);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
209
};
210
211
/** SHORT JOB DESCRIPTIONS (BROWSE JOBS AREA)
212
 *
213
 * @param {type} job
214
 * @param {type} demo
215
 * @param {type} locale
216
 * @returns {Element|JobPostAPI.populateJobSummary.jobCard}
217
 */
218
JobPostAPI.populateJobSummary = function(job, demo, locale){
219
220
    Utilities.debug?console.log("populating job"):null;
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
221
222
    // Create a job-card.
223
    var jobCard = document.createElement("a");
224
    jobCard.setAttribute("class", "job-card box med-1of2 lg-1of3");
225
    jobCard.setAttribute("id", "jobId_"+job.id);
226
    jobCard.setAttribute("title", job.title);
227
    jobCard.setAttribute("tabindex", 0);
228
    // jobCard.setAttribute("value", siteContent.viewButton);
229
    // jobCard.innerHTML = siteContent.viewButton;
230
    jobCard.setAttribute("onclick", "JobPostAPI.viewJobPoster("+job.id+")");
231
232
    var jobCardID = document.createElement("div");
233
    jobCardID.setAttribute("class", "jobId hidden");
234
    jobCardID.innerHTML = job.id;
235
236
    var jobCardWrapper = document.createElement("div");
237
    jobCardWrapper.setAttribute("class", "job-card__wrapper");
238
239
    // Create a job-card__title-wrapper.
240
    var jobCardTitleWrapper = document.createElement("div");
241
    jobCardTitleWrapper.setAttribute("class", "job-card__title-wrapper");
242
243
    var jobCardTitle = document.createElement("h3");
244
    jobCardTitle.setAttribute("class", "job-card__title");
245
    jobCardTitle.innerHTML = job.title;
246
247
    var jobCardDepartment = document.createElement("span");
248
    jobCardDepartment.setAttribute("class", "job-card__department");
249
    jobCardDepartment.innerHTML = job.department;
250
251
    // Create a job-card__content-wrapper.
252
    var jobCardContentWrapper = document.createElement("div");
253
    jobCardContentWrapper.setAttribute("class", "job-card__content-wrapper flex-grid");
254
255
    var jobCardContentBox1 = document.createElement("div");
256
    var jobCardContentBox2 = document.createElement("div");
257
    var jobCardContentBox3 = document.createElement("div");
258
    var jobCardContentBox4 = document.createElement("div");
259
260
    jobCardContentBox1.setAttribute("class", "box small-1of2");
261
    jobCardContentBox2.setAttribute("class", "box small-1of2");
262
    jobCardContentBox3.setAttribute("class", "box small-1of2");
263
    jobCardContentBox4.setAttribute("class", "box small-1of2");
264
265
    var jobCardLocationLabel = document.createElement("span");
266
    if (locale === "fr_CA" ){
267
        jobCardLocationLabel.innerHTML = "Emplacement";
268
    } else {
269
        jobCardLocationLabel.innerHTML = "Location";
270
    }
271
    var jobCardSalaryLabel = document.createElement("span");
272
    if (locale === "fr_CA" ){
273
        jobCardSalaryLabel.innerHTML = "Offre d'emploi";
274
    } else {
275
        jobCardSalaryLabel.innerHTML = "Salary";
276
    }
277
    var jobCardDurationLabel = document.createElement("span");
278
    if (locale === "fr_CA" ){
279
        jobCardDurationLabel.innerHTML = "Duration";
280
    } else {
281
        jobCardDurationLabel.innerHTML = "Duration";
282
    }
283
    var jobCardRemoteLabel = document.createElement("span");
284
    if (locale === "fr_CA" ){
285
        jobCardRemoteLabel.innerHTML = "Travail à distance";
286
    } else {
287
        jobCardRemoteLabel.innerHTML = "Remote Work";
288
    }
289
290
    var jobCardLocationWrapper = document.createElement("p");
291
    var jobCardLocationCity = document.createElement("span");
292
    jobCardLocationCity.innerHTML = job.location_city + "," + "&nbsp";
293
    var jobCardLocationProvince = document.createElement("span");
294
    jobCardLocationProvince.innerHTML = job.location_province;
295
296
    var jobCardSalary = document.createElement("p");
297
    jobCardSalary.setAttribute("id", "jobCardSalary"+job.id);
298
    if (locale === "en_CA"){
299
        jobCardSalary.innerHTML = "$" + job.remuneration_range_low.toLocaleString('en') + "–$" + job.remuneration_range_high.toLocaleString('en');
300
    } else {
301
        jobCardSalary.innerHTML = job.remuneration_range_low.toLocaleString('fr') + " $–" + job.remuneration_range_high.toLocaleString('fr') + " $";
302
    }
303
304
    var jobCardDuration = document.createElement("p");
305
    jobCardDuration.innerHTML = job.term_qty + " " + job.term_units + " " + siteContent.jobTerm ;
0 ignored issues
show
Bug introduced by
The variable siteContent seems to be never declared. If this is a global, consider adding a /** global: siteContent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
306
307
    var jobCardRemote = document.createElement("p");
308
    var jobCardRemoteID = "jobCardRemote" + jobCardID;
309
    jobCardRemote.setAttribute("id", jobCardRemoteID)
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
310
    //Load Other Hiring Manager Data
311
    DataAPI.getManagerProfile(job.manager_user_id, function(response) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
312
       var locale = TalentCloudAPI.getLanguageFromCookie();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
313
       var managerProfile = ManagerProfileAPI.parseManagerProfileResponse(response, locale);
0 ignored issues
show
Bug introduced by
The variable ManagerProfileAPI seems to be never declared. If this is a global, consider adding a /** global: ManagerProfileAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
314
       WorkEnvironmentAPI.loadWorkEnvironmentBrowseJobs(managerProfile.manager_profile_id, jobCardRemoteID);
0 ignored issues
show
Bug introduced by
The variable WorkEnvironmentAPI seems to be never declared. If this is a global, consider adding a /** global: WorkEnvironmentAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
315
    });
316
317
    // Create a job-card__footer-wrapper.
318
    var jobCardFooterWrapper = document.createElement("div");
319
    jobCardFooterWrapper.setAttribute("class", "job-card__footer-wrapper flex-grid");
320
321
    var jobCardFooterBox1 = document.createElement("div");
322
    var jobCardFooterBox2 = document.createElement("div");
323
324
    jobCardFooterBox1.setAttribute("class", "box med-1of2");
325
    jobCardFooterBox2.setAttribute("class", "box med-1of2");
326
327
    var jobCardDayValue = document.createElement("span");
328
    var jobCardApplicationValue = document.createElement("span");
329
330
    jobCardDayValue.innerHTML = Utilities.timeRemaining(job.close_date_time) + " " + siteContent.jobPosterTimeRemaining;
331
    jobCardApplicationValue.innerHTML = job.applicants_to_date + " " + siteContent.jobApplicantsSoFar;
332
333
    // Create a job-card__view-button.
334
    var jobCardViewButton = document.createElement("button");
335
    jobCardViewButton.setAttribute("class", "job-card__view-button");
336
    jobCardViewButton.setAttribute("tabindex", "-1");
337
    if (locale === "fr_CA" ){
338
        jobCardViewButton.innerHTML = "Voir le travail";
339
    } else {
340
        jobCardViewButton.innerHTML = "View Job";
341
    }
342
343
    // Build the job-card.
344
345
    // Build the job-card__title-wrapper.
346
    jobCardTitleWrapper.appendChild(jobCardTitle);
347
    jobCardTitleWrapper.appendChild(jobCardDepartment);
348
349
    // Build the job-card__content-wrapper.
350
    jobCardContentBox1.appendChild(jobCardLocationLabel);
351
352
    jobCardLocationWrapper.appendChild(jobCardLocationCity);
353
    jobCardLocationWrapper.appendChild(jobCardLocationProvince);
354
    jobCardContentBox1.appendChild(jobCardLocationWrapper);
355
356
    jobCardContentBox2.appendChild(jobCardSalaryLabel);
357
    jobCardContentBox2.appendChild(jobCardSalary);
358
359
    jobCardContentBox3.appendChild(jobCardDurationLabel);
360
    jobCardContentBox3.appendChild(jobCardDuration);
361
362
    jobCardContentBox4.appendChild(jobCardRemoteLabel);
363
    jobCardContentBox4.appendChild(jobCardRemote);
364
365
    jobCardContentWrapper.appendChild(jobCardContentBox1);
366
    jobCardContentWrapper.appendChild(jobCardContentBox2);
367
    jobCardContentWrapper.appendChild(jobCardContentBox3);
368
    jobCardContentWrapper.appendChild(jobCardContentBox4);
369
370
    // Build the job-card__footer-wrapper.
371
    jobCardFooterBox1.appendChild(jobCardDayValue);
372
    jobCardFooterBox2.appendChild(jobCardApplicationValue);
373
374
    jobCardFooterWrapper.appendChild(jobCardFooterBox1);
375
    jobCardFooterWrapper.appendChild(jobCardFooterBox2);
376
377
    // Build the job-card__wrapper.
378
    jobCardWrapper.appendChild(jobCardTitleWrapper);
379
    jobCardWrapper.appendChild(jobCardContentWrapper);
380
    jobCardWrapper.appendChild(jobCardFooterWrapper);
381
    jobCardWrapper.appendChild(jobCardViewButton);
382
383
    // Build the job-card.
384
    jobCard.appendChild(jobCardID);
385
    jobCard.appendChild(jobCardWrapper);
386
387
    return jobCard;
388
389
};
390
391
392
393
/**
394
 *
395
 * @returns {Number}
396
 */
397
JobPostAPI.getJobCount = function(){
398
    if(JobPostAPI.jobPosts){
399
        return JobPostAPI.jobPosts.length;
400
    }
401
    return 0;
402
};
403
404
/**
405
 *
406
 * @param {type} isFav
407
 * @param {type} jobPosterId
408
 * @returns {undefined}
409
 */
410
JobPostAPI.updateFavourite = function(isFav,jobPosterId){
411
412
    var contactToUpdate = document.getElementById(jobPosterId);
413
414
    var favImg = contactToUpdate.getElementsByClassName('favouriteImage')[0];
415
416
    var notFavouriteImage = new Image();
0 ignored issues
show
Bug introduced by
The variable Image seems to be never declared. If this is a global, consider adding a /** global: Image */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
417
    notFavouriteImage.src = "images/not-favourite.svg";
418
419
    var favouriteImage = new Image();
420
    favouriteImage.src = "images/favourite.svg";
421
422
    if(isFav){
423
        favImg.src = favouriteImage.src;
424
    }else{
425
        favImg.src = notFavouriteImage.src;
426
    }
427
428
    Utilities.debug?console.log(favImg.src):null;
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
429
}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
430
431
432
/**
433
 *
434
 * @returns {Boolean}
435
 */
436
JobPostAPI.viewJobPoster = function(jobId){
437
    DataAPI.getJobPoster(TalentCloudAPI.getLanguageFromCookie(),jobId, function(response) {
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
438
        var jobPoster = JobPostAPI.populateJobObject(JSON.parse(response));
439
        JobPostAPI.populateJobPoster(jobPoster);
440
    });
441
442
443
444
    if(UserAPI.hasSessionUser()) {
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
445
        document.getElementById("jobPosterButtonWrapper").classList.add("logged-in");
446
    } else {
447
        document.getElementById("jobPosterButtonWrapper").classList.remove("logged-in");
448
    }
449
450
    // New Subpage Hero Scripts
451
452
    Utilities.getHeroElements();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
453
454
    var browseHeroTitle = document.getElementById("browseHeroTitle");
455
    // var browseHeroPosterMetaData = document.getElementById("browseHeroPosterMetaData");
456
    browseHeroTitle.classList.remove("hidden");
457
    browseHeroTitle.setAttribute("aria-hidden", "false");
458
    // browseHeroPosterMetaData.classList.remove("hidden");
459
460
    // Mobile Menu Overflow Release
461
    document.body.style.overflowY = "visible";
462
463
    // Google Analytics
464
465
    ga('set', 'page', '/browse-jobs/'+jobId);
466
    ga('send', 'pageview');
467
468
    // Set scroll / focus to top of page
469
    window.scrollTo(0,0);
470
    AccessibilityAPI.focusElement("topPage");
0 ignored issues
show
Bug introduced by
The variable AccessibilityAPI seems to be never declared. If this is a global, consider adding a /** global: AccessibilityAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
471
    document.getElementById("topPage").focus();
472
473
};
474
475
JobPostAPI.localizeJobPoster = function() {
476
    if (siteContent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable siteContent is declared in the current environment, consider using typeof siteContent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
477
        document.getElementById('jobPosterHiringManagerPositionAtLabel').innerHTML = siteContent.at;
478
        // document.getElementById('accommodationRequestAt').innerHTML = siteContent.at;
479
        document.getElementById('jobPosterHiringManagerButton').innerHTML = siteContent.readMore;
480
        //document.getElementById("jobPosterNocLabel").innerHTML = siteContent.jobPosterNocLabel;
481
        document.getElementById("jobPosterIdLabel").innerHTML = siteContent.jobReferenceId;
482
483
        //Set language-specific labels
484
        document.getElementById("jobPosterSalaryRangeLabel").innerHTML = siteContent.jobSalaryRange;
485
        var applyButton = document.getElementById("jobPosterApplyButton");
486
        if (applyButton)
487
            applyButton.innerHTML = siteContent.applyNow;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
488
        var loginButton = document.getElementById("jobPosterLoginButton");
489
        if (loginButton)
490
            loginButton.innerHTML = siteContent.navigationLoginLink;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
491
        }
492
};
493
494
/** LONG JOB DESCRIPTIONS (VIEW JOB POSTER)
495
 *
496
 * @param JobPostAPI.JobPost jobData
497
 * @returns {undefined}
498
 */
499
JobPostAPI.populateJobPoster = function(jobData){
500
    var stateInfo = {pageInfo: 'view_job_poster', pageTitle: 'Talent Cloud: ' + jobData.title + ' (' + jobData.id + ')', jobId: jobData.id};
501
    document.title = stateInfo.pageTitle;
502
    history.pushState(stateInfo, stateInfo.pageInfo, '#Job/' + jobData.id);
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
503
    //console.log("asdfasdfsd = "+history.state.pageInfo);
504
505
    TalentCloudAPI.hideAllContent();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
506
507
    //Start requests for Hiring Manager data
508
    //Load Hiring Manager Name
509
    DataAPI.getManagerProfile(jobData.manager_user_id, function(response) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
510
       var managerProfile = JSON.parse(response);
511
       document.getElementById('jobPosterHiringManagerName').innerHTML = managerProfile.user.name;
512
       // document.getElementById('jobPosterHiringManagerNameAccommodation').innerHTML = managerUser.user.name;
513
514
       if (locale === "en_CA"){
0 ignored issues
show
Bug introduced by
The variable locale seems to be never declared. If this is a global, consider adding a /** global: locale */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
515
           var subject = "?subject=TalentCloud Accommodation Request for Job ID #" + jobData.id;
0 ignored issues
show
Unused Code introduced by
The variable subject seems to be never used. Consider removing it.
Loading history...
516
       } else {
517
           var subject = "?subject=Demande d'hébergement TalentCloud pour le numéro d'identification du travail " + jobData.id;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable subject already seems to be declared on line 515. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like subject was already defined.
Loading history...
518
       }
519
       // document.getElementById('jobPosterHiringManagerEmail').innerHTML = managerUser.user.email;
520
       // document.getElementById('jobPosterHiringManagerEmail').href = "mailto:" + managerUser.user.email + subject;
521
    });
522
523
    // Subnav Content
524
    var jobPosterSubnavJobTitle = document.getElementById("jobPosterSubnavJobTitle");
525
    var jobPosterSubnavDepartment = document.getElementById("jobPosterSubnavDepartment");
526
    jobPosterSubnavJobTitle.innerHTML = jobData.title;
527
    jobPosterSubnavDepartment.innerHTML = jobData.department;
528
529
    //Return to job poster from hiring manager profile
530
     var jobPosterBack1 = document.getElementById("jobPosterBackButton");
531
     jobPosterBack1.setAttribute("onclick", "JobPostAPI.viewJobPoster("+jobData.id+")");
532
     var jobPosterBack2 = document.getElementById("jobPosterBackButton2");
533
     jobPosterBack2.setAttribute("onclick", "JobPostAPI.viewJobPoster("+jobData.id+")");
534
535
    //Load Hiring Manager Image
536
    var hiringManagerProfilePic = document.getElementById('jobPosterCultureManagerProfilePhoto');
537
    ProfilePicAPI.refreshProfilePicBackground(jobData.manager_user_id, hiringManagerProfilePic);
0 ignored issues
show
Bug introduced by
The variable ProfilePicAPI seems to be never declared. If this is a global, consider adding a /** global: ProfilePicAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
538
    //Load Other Hiring Manager Data
539
    DataAPI.getManagerProfile(jobData.manager_user_id, function(response) {
540
       var locale = TalentCloudAPI.getLanguageFromCookie();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
541
       var managerProfile = ManagerProfileAPI.parseManagerProfileResponse(response, locale);
0 ignored issues
show
Bug introduced by
The variable ManagerProfileAPI seems to be never declared. If this is a global, consider adding a /** global: ManagerProfileAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
542
       document.getElementById('jobPosterHiringManagerTitle').innerHTML = managerProfile.position;
543
544
       //Get department ID
545
       var dept_id = parseInt(managerProfile.department_id);
546
       //Convert to localized value
547
       var department_text = LookupAPI.getLocalizedLookupValue("department", dept_id);
0 ignored issues
show
Bug introduced by
The variable LookupAPI seems to be never declared. If this is a global, consider adding a /** global: LookupAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
548
       //Assign to HTML element
549
       document.getElementById("jobPosterHiringManagerDepartment").innerHTML = department_text;
550
551
       /*Truncating Manager About Me*/
552
        //Get rid of read more feature. User must click read profile to read all information.
553
       var len = 250;
554
       if (managerProfile.about_me !== null && managerProfile.about_me.length > 0) {
555
            var fullText = managerProfile.about_me;
556
            var id = "jobPosterHiringManagerAboutMe";
557
            var aboutMe = document.getElementById(id);
558
559
560
561
            if(fullText.length > len){
562
               var trunc = fullText.substring(0, len).replace(/\w+$/, '');
563
               var remainder = fullText.substring(len, fullText.length);
0 ignored issues
show
Unused Code introduced by
The variable remainder seems to be never used. Consider removing it.
Loading history...
564
565
                aboutMe.innerHTML = trunc.concat("...");
566
567
               /*
568
               //Code for repurposing
569
               var showMoreAnchor = document.createElement("a");
570
               showMoreAnchor.setAttribute("id", id + "_MoreLink");
571
               showMoreAnchor.setAttribute("href", "javascript:void(0)");
572
               showMoreAnchor.setAttribute("onclick", "JobPostAPI.showMoreHiringManagerSummary(\"" + id + "\")");
573
               showMoreAnchor.innerHTML = "..."; // Append this to the truncating
574
575
               var showLessAnchor = document.createElement("a");
576
               showLessAnchor.setAttribute("id", id + "_LessLink");
577
               showLessAnchor.setAttribute("class", "hidden");
578
               showLessAnchor.setAttribute("href", "javascript:void(0)");
579
               showLessAnchor.setAttribute("onclick", "JobPostAPI.showLessHiringManagerSummary(\"" + id  + "\")");
580
               showLessAnchor.innerHTML = "Less";
581
582
583
               var overflowSpan = document.createElement("span");
584
               overflowSpan.setAttribute("class", "hidden");
585
               overflowSpan.setAttribute("id", id + "_Overflow");
586
587
               var remainderText = document.createTextNode(remainder);
588
589
               overflowSpan.appendChild(remainderText);
590
591
               var truncatedSpan = document.createElement("span");
592
               var truncateText = document.createTextNode(trunc);
593
594
               truncatedSpan.appendChild(truncateText);
595
               truncatedSpan.appendChild(overflowSpan);
596
597
               var space = document.createTextNode( '\u00A0' );
598
599
               aboutMe.appendChild(truncatedSpan);
600
               aboutMe.appendChild(space);
601
               aboutMe.appendChild(showMoreAnchor);
602
               aboutMe.appendChild(showLessAnchor);
603
               */
604
605
            } else {
606
                aboutMe.innerHTML = fullText;
607
            }
608
            /*End Truncating*/
609
        }
610
611
        if(managerProfile.manager_profile_id !== null){
612
            WorkEnvironmentAPI.loadWorkEnvironmentSummary(managerProfile.manager_profile_id);
0 ignored issues
show
Bug introduced by
The variable WorkEnvironmentAPI seems to be never declared. If this is a global, consider adding a /** global: WorkEnvironmentAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
613
            TeamCultureAPI.loadTeamCultureSummary(managerProfile.manager_profile_id);
0 ignored issues
show
Bug introduced by
The variable TeamCultureAPI seems to be never declared. If this is a global, consider adding a /** global: TeamCultureAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
614
        }
615
    });
616
617
    //TODO: add more
618
619
   //set hidden values
620
   document.getElementById("jobPosterJobId").value = jobData.id;
621
   document.getElementById('jobPosterHiringManagerUserId').value = jobData.manager_user_id;
622
623
    //Header
624
    if (jobData.title === "") {
625
        jobData.title = "No Title";
626
    }
627
    document.getElementById("jobPosterTitle").innerHTML = jobData.title;
628
    document.getElementById("jobPosterDepartment").innerHTML = jobData.department;
629
    document.getElementById("jobPosterCity").innerHTML = jobData.location_city;
630
    document.getElementById("jobPosterProvince").innerHTML = jobData.location_province;
631
    //document.getElementById("jobPosterNocValue").innerHTML = jobData.noc;
632
    document.getElementById("jobPosterIdValue").innerHTML = jobData.id;
633
634
    //Datapoints
635
    if (locale === "en_CA"){
0 ignored issues
show
Bug introduced by
The variable locale seems to be never declared. If this is a global, consider adding a /** global: locale */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
636
        document.getElementById("jobPosterSalaryRangeValue").innerHTML = "$" + jobData.remuneration_range_low.toLocaleString('en') + " ~ $" + jobData.remuneration_range_high.toLocaleString('en');
637
    } else {
638
        document.getElementById("jobPosterSalaryRangeValue").innerHTML = jobData.remuneration_range_low.toLocaleString('fr') + " $ ~ " + jobData.remuneration_range_high.toLocaleString('fr') + " $";
639
    }
640
641
    document.getElementById("jobPosterTermValue").innerHTML = jobData.term_qty + " " + jobData.term_units;
642
    document.getElementById("jobPosterJobLevelValue").innerHTML = jobData.classification;
643
    document.getElementById("jobPosterClearanceLevelValue").innerHTML = jobData.security_clearance;
644
    document.getElementById("jobPosterLanguageValue").innerHTML = jobData.language_requirement;
645
646
647
648
    // Split timestamp into [ Y, M, D, h, m, s ]
649
    var t = jobData.start_date.split(/[- :]/);
650
    // Apply each element to the Date function
651
    var d = new Date(t[0], t[1]-1, t[2], t[3] || 0, t[4] || 0, t[5] || 0);
652
653
    // Get localized month
654
    if (locale === "en_CA"){
655
        var month = d.toLocaleString("en", {month: "long"});
656
    } else {
657
        var month = d.toLocaleString("fr", {month: "long"});
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable month already seems to be declared on line 655. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like month was already defined.
Loading history...
658
    }
659
    // Formatting i.e. April, 2018
660
    var startDateFormatted = month + ", " + d.getFullYear();
0 ignored issues
show
Bug introduced by
The variable month seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
661
662
    document.getElementById("jobPosterStartDateValue").innerHTML = startDateFormatted;
663
664
    if (jobData.impact === "")
665
        jobData.impact = "N/A";
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
666
    document.getElementById("jobPosterImpact").innerHTML = jobData.impact;
667
668
    var keyTaskList = document.getElementById("jobPosterKeyTasks");
669
    if (jobData.key_tasks.length === 0) {
670
        jobData.key_tasks.push("N/A");
671
    }
672
    JobPostAPI.setItemsForListElement(keyTaskList, jobData.key_tasks, "keyTaskItem");
673
674
    var coreCompetencyList = document.getElementById("jobPosterCoreCompetencies");
675
    var coreCompetencyValues = [];
676
    if (jobData.core_competencies.length === 0) {
677
        coreCompetencyValues.push("N/A");
678
    } else {
679
        var core_competencies = jobData.core_competencies;
680
        for (var i = 0; i < core_competencies.length; i++) {
681
            coreCompetencyValues.push(core_competencies[i].value);
682
        }
683
    }
684
    JobPostAPI.setItemsForListElement(coreCompetencyList, coreCompetencyValues, "coreCompetencyItem");
685
686
    var developingCompetencyList = document.getElementById("jobPosterDevelopingCompetencies");
687
    var devCompetencyValues = [];
688
    if (jobData.developing_competencies.length === 0) {
689
        devCompetencyValues.push("N/A");
690
    } else {
691
        var developing_competencies = jobData.developing_competencies;
692
        for (var i = 0; i < developing_competencies.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 680. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like i was already defined.
Loading history...
693
            devCompetencyValues.push(developing_competencies[i].value);
694
        }
695
    }
696
    JobPostAPI.setItemsForListElement(developingCompetencyList, devCompetencyValues, "developingCompetencyItem");
697
698
    // Show Time Remaining & Number of Applicants
699
    var jobTimeRemaining = document.getElementById("jobPosterTimeRemainingData");
700
    jobTimeRemaining.innerHTML = Utilities.timeRemaining(jobData.close_date_time);
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
701
    var jobApplicants = document.getElementById("jobPosterApplicantsData");
702
    jobApplicants.innerHTML = jobData.applicants_to_date;
703
704
    document.getElementById("viewJobPosterSection").classList.remove("hidden");
705
706
    //TODO: fix this when working on jobPoserApplications
707
    //var jobSeekerProfileId = document.getElementById("profile_id").value;
708
};
709
710
JobPostAPI.showMoreHiringManagerSummary = function(id){
711
    document.getElementById(id+'_Overflow').classList.remove("hidden");
712
    document.getElementById(id+'_MoreLink').classList.add("hidden");
713
    document.getElementById(id+'_LessLink').classList.remove("hidden");
714
};
715
716
JobPostAPI.showLessHiringManagerSummary = function(id){
717
    document.getElementById(id+'_Overflow').classList.add("hidden");
718
    document.getElementById(id+'_MoreLink').classList.remove("hidden");
719
    document.getElementById(id+'_LessLink').classList.add("hidden");
720
};
721
722
JobPostAPI.setItemsForListElement = function(element, items, itemClassAtribute) {
723
    //First, clear existing items in element
724
    while( element.lastChild )
725
        element.removeChild( element.lastChild );
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
726
727
    for (var i=0; i<items.length; i++) {
728
        if (items[i].trim()) {
729
            var item = document.createElement("li");
730
            if (itemClassAtribute)
731
                item.setAttribute("class", itemClassAtribute);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
732
            var p = document.createElement("p");
733
            var text = document.createTextNode(items[i]);
734
735
            p.appendChild(text);
736
            item.appendChild(p)
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
737
            element.appendChild(item);
738
        }
739
    }
740
};
741
742
/**
743
 *
744
 * @returns {undefined}
745
 */
746
JobPostAPI.hideJobPoster = function(){
747
    var jobPosterSection = document.getElementById("viewJobPosterSection");
748
    jobPosterSection.classList.add("hidden");
749
750
    JobPostAPI.showBrowseJobs();
751
};
752